﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PDF2TXT.Start
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnPdf2Img_Click(object sender, EventArgs e)
        {
            List<string> outFiles = new List<string>();
            string pdfPath = this.txtFilePDF.Text.Trim();
            string outPath = "G:\\test\\img";            

            PdfConvertHelper pdfConvertHelper = new PdfConvertHelper();
            
            outFiles = pdfConvertHelper.PdfToImagePdfViewer(pdfPath, outPath);
            this.lbOutFiles.Items.AddRange(outFiles.ToArray());
        }

        private void btnSelectFile_Click(object sender, EventArgs e)
        {            
            OpenFileDialog openFileDialog = new OpenFileDialog();

            // 设置文件选择对话框的标题
            openFileDialog.Title = "请选择文件";

            // 设置过滤选项，让用户只能打开某些类型的文件
            openFileDialog.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*";

            string selectedFileName;

            // 显示文件选择对话框
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                // 获取用户选择的文件名
                selectedFileName = openFileDialog.FileName;

                // 然后你可以用这个文件名做你想做的事情
                this.txtFilePDF.Text = selectedFileName;
            }

            

            openFileDialog.Dispose();
        }

        private void btnImg2Txt_Click(object sender, EventArgs e)
        {
            string imgPath = string.Empty;
            string outText = string.Empty;

            imgPath = this.txtFileImg.Text.Trim();

            OcrHelper ocrHelper = new OcrHelper();
            outText = ocrHelper.RecognizeTextFromImage(imgPath);

            txtOutText.Text = this.richTextBox1.Text = outText;
            


        }
    }
}
